﻿using System.Collections.Generic;
using System.Text;

namespace tiny_compiler
{
	public class ReadKey :
		IOperator
	{
		public ReadKey(string _targetValueName)
		{
			m_targetValueName = _targetValueName;
		}

		#region IOperator Members

		public int Length
		{
			get { return Compiler.NameLength + Compiler.LengthLength + Compiler.NumberLength; }
		}

		public string Name
		{
			get { return string.Empty; }
		}

		public void Resolve(IEnumerable<IOperator> _operators)
		{
			m_targetValue = _operators.Offset(m_targetValueName);
		}

		public void Append(StringBuilder _data)
		{
			_data.Append(Compiler.ReadKeyName);
			_data.Append(CompilerUtility.ConvertLength(Length));
			_data.Append(CompilerUtility.ConvertNumber(m_targetValue));
		}

		#endregion

		private string m_targetValueName;
		private int m_targetValue;
	}
}
